package com.zjcode.cdcer.controller;

import com.chinatechstar.component.commons.controller.BaseController;
import com.chinatechstar.component.commons.result.ListResult;
import com.chinatechstar.component.commons.result.ResultBuilder;
import com.chinatechstar.component.commons.supports.PageData;
import com.zjcode.cdcer.model.basic.JsonObj;
import com.zjcode.cdcer.service.FollowUpListOfficeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ZQM
 * @date 2023/10/9 15:00
 */
@RestController
@RequestMapping("/v1/followupListOffice")
public class FollowUpListOfficeController extends BaseController {

    @Autowired
    private FollowUpListOfficeService followUpListOfficeService;

    /**
     * 存入正式库
     */
    @PostMapping("/add")
    public JsonObj add(@RequestBody PageData pageData) {
        return followUpListOfficeService.add(pageData);
    }

    /**
     * 列表查询
     */
    @PostMapping("/selList")
    public ListResult<Object> selList(@RequestBody PageData pageData) {
        return ResultBuilder.buildListSuccess(followUpListOfficeService.selList(pageData));
    }

    /**
     * 查询详细信息（根据id）
     */
    @GetMapping("/selById")
    public JsonObj selById(@RequestParam String id) {
        return followUpListOfficeService.selById(id);
    }

    /**
     * 退回
     */
    @PostMapping("/followUpListOfficeReturn")
    public JsonObj followUpListOfficeReturn(@RequestBody PageData pageData) {
        return followUpListOfficeService.followUpListOfficeReturn(pageData);
    }

    /**
     * 导出
     */
    @PostMapping("/queryAllExportData")
    public JsonObj queryAllExportData(@RequestBody PageData pageData) {
        List<LinkedHashMap<String,Object>> list  = followUpListOfficeService.queryAllExportData(pageData);
        Map<String,Object> map = new HashMap<>();
        map.put("data",list);
        return JsonObj.success(map);
    }


    @PostMapping(value = "/importGJData")
    @ApiOperation("导入（国家格式）")
    public JsonObj importGJData(@RequestParam("file") MultipartFile file, HttpServletResponse response)
            throws IOException {
        PageData pageData = getPageData();
        String userId = (String) pageData.get("user");
        return followUpListOfficeService.importGJData(file,response,userId);
    }
}
